package cn.wowjoy.pda.android_pharmacy.mvvm.vm;

import java.util.ArrayList;

import cn.wowjoy.pda.android_pharmacy.common.core.BaseViewModel;
import cn.wowjoy.pda.android_pharmacy.model.xmlEntity.inHospitalPatientInfo.InHospitalPillSingleBeen;

/**
 * Created by Administrator on 2017/9/1.
 */

public class InHospitalPillProgressViewModel extends BaseViewModel {
    //每次被移除的一个Been
    public InHospitalPillSingleBeen remove;
    public ArrayList<InHospitalPillSingleBeen> FirstTotal;
    //第一次的全部数据 实体类   每取一次就把第一个移出去，放入到另外一个集合
    public ArrayList<InHospitalPillSingleBeen>   mMoveBaens;
//    public  ArrayList<InHospitalPillSingleBeen> mTestBeen = new ArrayList<>();

    public void show(ArrayList<InHospitalPillSingleBeen> mDatas) {
        if (null == FirstTotal)
            FirstTotal = new ArrayList<>();
        FirstTotal.clear();
        FirstTotal.addAll(mDatas);

        if (null == mMoveBaens)
            mMoveBaens = new ArrayList<>();
        mMoveBaens.clear();
        mMoveBaens.addAll(mDatas);
    }
    //获取当前集合中即将移除的第一个
    public InHospitalPillSingleBeen remove() {
        if (null != mMoveBaens) {
            if (mMoveBaens.size() == 1) {
                return mMoveBaens.get(0);
            }
//            mMoveBaens.remove(0);
//            return mMoveBaens.get(0);
            remove=mMoveBaens.remove(0);
            return remove;
        }
        return null;
    }
    //获取移除后当前集合中的第一个
    public InHospitalPillSingleBeen getFirst() {
        if (null != mMoveBaens)
            return mMoveBaens.get(0);

        return null;
    }
    //计算当前集合中已经被检查的
    public int calcNum(){
        int num=0;
        for(InHospitalPillSingleBeen inHospitalPillSingleBeen : mMoveBaens ){
            if(inHospitalPillSingleBeen.isCheck()){
                num++;
            }
        }
        return num;
    }
    /**
     * 方案一
     * 1.首先判断是否在集合中
     * 2.判断匹配的药的数量是否为0
     * 3.不为0就 -1  为 0但是还能扫到 说明有问题
     * 4.最终集合中的所有药的数量属性均为0 不然视为有问题
     *
     *方案二  只考虑种类  不考虑单个药品的数量
     * 1.首先判断是否在药品种类集合中
     * 2,匹配就把它从集合中移出去，不匹配就弹框提示
     * 3.最终集合数据为0
     *
     */
    public InHospitalPillSingleBeen checkExist(String stringExtra){
        if(null != mMoveBaens && mMoveBaens.size()>0){
            for (InHospitalPillSingleBeen inHospitalPillSingleBeen : mMoveBaens){
                if(null != inHospitalPillSingleBeen.getDJXBHM() && inHospitalPillSingleBeen.getDJXBHM().equals(stringExtra)){
                    return inHospitalPillSingleBeen;
                }
//                if( null != stringExtra && stringExtra.length()>7){
//                    if(null != InHospitalPillSingleBeen.getYPJGBM() && InHospitalPillSingleBeen.getYPJGBM().equals(stringExtra.substring(0,7))){
//                        return InHospitalPillSingleBeen;
//                    }
//                }
//                if(null != InHospitalPillSingleBeen.getKFWZMC() && InHospitalPillSingleBeen.getKFWZMC().length()>7 &&  InHospitalPillSingleBeen.getKFWZMC().substring(0,7).equals(stringExtra)){
//                    return InHospitalPillSingleBeen;
//                }
            }
        }
        return null;
    }
    public  boolean   checkSecond(InHospitalPillSingleBeen InHospitalPillSingleBeen) {
        if (null != mMoveBaens && mMoveBaens.size() > 0) {
            for (InHospitalPillSingleBeen i : mMoveBaens) {
                if (null != i.getDJXBHM() && i.getDJXBHM().equals(InHospitalPillSingleBeen.getDJXBHM())) {
                    //匹配成功
                    if (i.isCheck()) {
                        return false;
                    }
                    i.setCheck(true);
                    return true;
                }
            }
        }
        return false;
    }

    public boolean checkTotal(){
        for(InHospitalPillSingleBeen InHospitalPillSingleBeen : mMoveBaens){
            if(!InHospitalPillSingleBeen.isCheck()){
                return false;
            }
        }
        return true;
    }
}
